﻿using System;
using System.Windows;
using MovieBuddy.Controls;
using MovieBuddy.Helpers;

namespace MovieBuddy.Dialogs
{
    /// <summary>
    /// Interaction logic for EditImageMovieItemDialog.xaml
    /// </summary>
    public partial class EditImageMovieItemDialog : Window
    {
        public event EventHandler<SaveButtonClickedEventArgs> SaveClicked;

        public EditImageMovieItemDialog(string type, string name, string imageFile)
        {
            InitializeComponent();
            Title = string.Format("Edit {0} {1}", type, name);
            nameBox.Text = name;
            imageFilePicker.FileName = imageFile;
        }

        private void ImagePicked(object sender, FilePickerUpdatedEventArgs e)
        {
            imagePreview.Source = ImageCache.GetImage(e);
        }

        private void CancelButtonClick(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void SaveButtonClick(object sender, RoutedEventArgs e)
        {
            SaveClicked(this, new SaveButtonClickedEventArgs(nameBox.Text, imageFilePicker.FileName));
            Close();
        }

        public class SaveButtonClickedEventArgs : EventArgs
        {
            public readonly string Name;
            public readonly string Image;

            public SaveButtonClickedEventArgs(string name, string image)
            {
                Name = name;
                Image = image;
            }
        }
    }
}
